<?php
if (!defined("IN_OP"))
{
    exit("You can't access this file directly...");
}
require_once( "class_3d/CheckMode_3d.php" );
$gametype = intval(getvar("gametype"));
$chk = new CheckMode_3d($curruser['acl'], 3, $gametype);
$chk->checkShow3dPage();
$show3D3S = $chk->show3D3S;
unset($chk);
$tbl = $g_gametype_3d[$gametype]['en'];
$tblName = $g_gametype_3d[$gametype]['ch'];
$title = "系统管理员 注销{$tblName}注单";
$ui = new UI_3D();
$ui->header();
include( "admin_menu_3d.php" );
$conf = new Config();
$myDB = new DB();
if ($show3D3S == 0 && $conf->get("calcbet_{$tbl}") == 1)
{
    $ui->showErrorPage("<p class=error>{$tblName}已经在颁奖过帐中，无法取消注单！</p>");
    exit();
}
$reBetTotalFlag = false;
if ($curruser['acl'] == 255)
{
    $reBetTotalFlag = true;
}
include_once( "class_3d/MyLotto_3d.php" );
$MyLotto_3d = new MyLotto_3d($gametype);
$chkVal = false;
$today = date("Y-m-d");
switch ($show3D3S)
{
    case 0 :
        /*if ($lotto_data = $MyLotto_3d->getLotto3DByDate($today))
        {
            $datehi = date("Hi");
            if ($conf->get("stopbet_{$tbl}") <= $datehi)
            {
                $ui->showErrorPage("<p class=error>目前非{$tblName}下单时段！</p>");
                exit();
            }
            else
            {
                if ($datehi < $conf->get("startbet_{$tbl}"))
                {
                    $ui->showErrorPage("<p class=error>目前非{$tblName}下单时段！</p>");
                    exit();
                }
                else
                {
                    $chkVal = true;
                }
            }
        }
        else
        {
            $ui->showErrorPage("<p class=error>目前无{$tblName}可下注期数！</p>");
            exit();
        }*/
        break;
    case 1 :
        if ($lotto_data = $MyLotto_3d->getLotto3SByDateTime())
        {
            $chkVal = true;
        }
        else
        {
            $ui->showErrorPage("<p class=error>目前暂无{$tblName}可下注期数！</p>");
            exit();
        }
        break;
}
require_once( "class_3d/class.lotto3d.php" );
$Lotto3dClass = new lotto3d($gametype);
$betReflash = intval(getvar("betReflash"));
$postTime = $conf->get("paper_post_bet");
$todayOpen = date("Hi") <= $postTime ? date("Y-m-d", strtotime("-1 day")) : date("Y-m-d");
if (isset($_GET['fineAccID']))
{
    $xyidTitle = array(0 => "", 1 => "X盘", 2 => "Y盘");
    $fineAcc = getvar("fineAcc");
    $sql = "SELECT id, acl FROM k_user WHERE account = '{$fineAcc}' AND acl between 1 AND 5 LIMIT 1";
    $rs = getdb($sql);
    if ($rs->eof)
    {
        echo "<p>查无该帐号资料!</p>";
    }
    else
    {
        $fineAccID = $rs->f['id'];
        $fineAccACL = $rs->f['acl'];
        $sql = "SELECT id, open, round" . ( $show3D3S ? ", startbet, stopbet" : "" ) . " FROM lotto_{$tbl} where open = '{$todayOpen}' " . ( $show3D3S ? "AND '" . date("Y-m-d H:i:s") . "' between startbet and stopbet" : "" ) . " LIMIT 1";
        $rs = getdb($sql);
        if ($rs->eof)
        {
            $ui->showErrorPage("<p class=error>目前无{$tblName}可下注期数！</p>");
            exit();
        }
        $lotto_id = $rs->f['id'];
        $open = $rs->f['open'];
        $round = $rs->f['round'];
        if ($show3D3S)
        {
            $startbet = substr($rs->f['startbet'], 0 - 8);
            $stopbet = substr($rs->f['stopbet'], 0 - 8);
        }
        $bettypesubid = getvar("bettypesubid");
        $betname = judge_type($gametype, true);
        if ($bettypesubid != "" && $bettypesubid != 0 - 1)
        {
            $bettypesubidArr = explode("_", $bettypesubid);
            $bettypesubidArr[0] = intval($bettypesubidArr[0]);
            $bettypesubidArr[1] = intval($bettypesubidArr[1]);
            $bettypesubidStr = " AND bettype = {$bettypesubidArr[0]} AND subid = {$bettypesubidArr[1]} ";
            $titleStr = $betname[$bettypesubid];
        }
        else
        {
            $bettypesubidStr = "";
            $titleStr = "";
        }
        $sql = "SELECT * FROM bet" . ( $fineAccACL == 1 ? "" : "2" ) . "_{$tbl} WHERE user_id = {$fineAccID} AND lotto_id = {$lotto_id} AND rame IN (0,2) {$bettypesubidStr}";
        $page = intval(getvar("page"));
        if (!$page)
        {
            $page = 1;
        }
        $rs = getdb($sql, $page, 10);
        echo "<form method='post' action='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}' onsubmit='return confirm(\"确定要取消勾选的注单吗?\")'>";
        echo "<input type='hidden' name='bet' value='" . ( $fineAccACL == 1 ? "1" : "2" ) . "' />";
        echo "<table class='tblMy3D' id='tblFineID'>";
        echo "<tr class=\"paperAll\"><td colspan='12'>第{$round}期 {$open} ";
        if ($show3D3S)
        {
            echo " ({$startbet} 开盘 ~ {$stopbet} 关盘)";
        }
        echo "帐号: {$fineAcc}";
        if ($fineAccACL == 1)
        {
            echo "<strong>会员下注注单</strong>";
        }
        else
        {
            echo "<strong>管理走飞注单</strong>";
        }
        if ($titleStr)
        {
            echo " 【查询玩法: {$titleStr}】";
        }
        echo " </td></tr>";
        if ($rs->eof)
        {
            echo "<tr><td class=\"msgBox-yellow\" colspan=\"12\">查无【" . $tblName . "】可取消注单</td></tr>";
        }
        else
        {
            echo "<tr class=\"paperAll\" align=center><td>勾</td><td nowrap>单号 / 时间</td><td nowrap>会员 / 退水</td><td nowrap>下注玩法</td><td nowrap>盘类 / 期数 / 开奖日期</td><td nowrap>下注内容</td><td nowrap>下注金额</td><td nowrap>赔率</td><td nowrap>备注</td><td nowrap>IP</td></tr>";
            $rateNum = 3;
            $littleNum = 0;
            $littleAmount = 0;
            $littleBack = 0;
            $littleB1 = 0;
            $backType = "back" . $fineAccACL;
            $backRsType = "a" . $fineAccACL;
            $backRsTypeB = "b" . $fineAccACL;
            while (!$rs->eof)
            {
                echo "<tr class=\"td2\">";
                if ($rs->f['rame'] == 2)
                {
                    echo "<td align='center'>--</td>";
                }
                else
                {
                    echo "<td><input type='checkbox' name='id[]' value='" . $rs->f['id'] . "' /></td>";
                }
                echo "<td nowrap><font color=\"green\">" . $rs->f['id'] . "</font>&nbsp;&nbsp;" . date("m-d H:i:s", $rs->f['createtime']) . "</td>";
                echo "<td nowrap>{$fineAcc}&nbsp;&nbsp;<font color=\"green\">" . round(100 - $rs->f[$backType], 2) . "</font></td>";
                echo "<td nowrap class=\"paper" . $g_gametype_3d[$gametype]['en'] . "\">" . $g_gametype_3d[$gametype]['ch'] . "</td>";
                if ($fineAccACL == 1)
                {
                    echo "<td nowrap>" . $g_disk_name[$rs->f['disk']] . "&nbsp;/&nbsp;";
                }
                else
                {
                    echo "<td nowrap>";
                }
                echo "{$round}期&nbsp;<font color=\"green\">{$open}</font></td>";
                if ($gametype == 0)
                {
                    echo "<td nowrap>" . GetBetContent($rs->f['bettype'], $rs->f['numbers'], $rs->f['amount']) . "</td>";
                }
                else
                {
                    echo "<td nowrap>";
                    if ($gametype == 7)
                    {
                        echo "<font class='colorXY'>" . $xyidTitle[$rs->f['xyid']] . "</font>";
                    }
                    echo "【" . $betname[$rs->f['bettype'] . "_" . $rs->f['subid']] . "】&nbsp;" . nl2br($rs->f['line_nums']) . "</td>";
                }
                if (20000 < $rs->f['amount'])
                {
                    $color = "alert2";
                }
                else if (10000 < $rs->f['amount'])
                {
                    $color = "alert1";
                }
                else
                {
                    $color = "";
                }
                echo "<td nowrap align=\"right\" class=\"" . $color . "\">" . $rs->f['amount'] . "</td>";
                echo "<td nowrap align=\"right\">" . floatval($rs->f['rate']) . "</td>";
                if ($rs->f['rame'] == 1)
                {
                    $note = "<font color=red>- 逾时 -</td>";
                }
                else if ($rs->f['rame'] == 2)
                {
                    $note = "<font color=red>- 取消 -</td>";
                }
                else if ($rs->f['rame'] == 3)
                {
                    $note = "<font color=red>- 异常 -</td>";
                }
                else
                {
                    $note = "";
                    $littleNum += 1;
                    $littleAmount += $rs->f['amount'];
                    $littleBack += $rs->f[$backRsType];
                    $littleB1 += $rs->f[$backRsTypeB];
                }
                echo "<td nowrap>" . $note . "</td>";
                echo "<td nowrap>" . $rs->f['ip'] . "</td>";
                echo "</tr>";
                $rs->movenext();
            }
            $totalrecords = 0;
            $totalAmount = 0;
            $totalA1 = 0;
            $totalB1 = 0;
            echo "<tr><td class=\"msgBox-yellow\" colspan=\"12\"><input type=\"submit\" value=\"确定取消\" />";
            echo "<input type=button name='reset' value='回取消页面' onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
            echo "</td></tr>";
            echo "<tr><td class=\"paperAll\" colspan=\"12\">" . $rs->pagelink() . "</td></tr>";
        }
        echo "</table>";
        echo "</form>";
        echo " <script>";
        echo " $(document).ready(function() {";
        echo " $('#tblFineID tr')";
        echo " .filter(':has(:checkbox:checked)')";
        echo " .addClass('td17')";
        echo " .end()";
        echo "  .click(function(event) {";
        echo " $(this).toggleClass('td17');";
        echo " if (event.target.type !== 'checkbox') {";
        echo " $(':checkbox', this).attr('checked', function() {";
        echo " return !this.checked;";
        echo " });";
        echo " }";
        echo " });";
        echo " });</script> ";
    }
    echo "<input type=button name='reset' value='回取消页面' onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
}
else if ($show3D3S && isset($_POST['dlbByLottoID']))
{
    $lottoIdTime = intval(getvar("lottoIdTime"));
    $sql = "SELECT * FROM lotto_{$tbl} WHERE id = {$lottoIdTime} LIMIT 1";
    $rs = getdb($sql);
    if ($rs->eof)
    {
        echo "<p>查无该期期数资料!</p>";
    }
    else
    {
        if (isset($_POST['ok']))
        {
            $memOKALL = 0;
            $roundDB = $rs->f['round'];
            getdb("update bet_{$tbl} set rame=2,state=0 where lotto_id = {$lottoIdTime} and rame=0");
            $updateId = getdb("!!select id from bet_{$tbl} where lotto_id = {$lottoIdTime} and rame=2 and state=0 ");
            $memOK = 0;
            while (!$updateId->eof)
            {
                $Lotto3dClass->getBet_3D($updateId->f[0]);
                $updateId->next();
                ++$memOK;
            }
            $memOKALL += $memOK;
            echo "<div class='td2'>{$tblName} 第{$roundDB}期 会员注单取消完成，共{$memOK}笔</div>";
            getdb("update bet2_{$tbl} set rame=2,state=0 where lotto_id = {$lottoIdTime} and rame=0");
            $updateId = getdb("!!select id from bet2_{$tbl} where lotto_id = {$lottoIdTime} and rame=2 and state=0 ");
            $memOK = 0;
            while (!$updateId->eof)
            {
                $Lotto3dClass->getBet2_3D($updateId->f[0]);
                $updateId->next();
                ++$memOK;
            }
            $memOKALL += $memOK;
            echo "<div class='td2'>{$tblName} 第{$roundDB}期 管理走飞注单取消完成，共{$memOK}笔</div>";
            getdb("update bet8_{$tbl} set rame=2,state=0 where lotto_id = {$lottoIdTime} and rame=0");
            $updateId = getdb("!!select id from bet8_{$tbl} where lotto_id = {$lottoIdTime} and rame=2 and state=0 ");
            $memOK = 0;
            while (!$updateId->eof)
            {
                $Lotto3dClass->getBet8_3D($updateId->f[0]);
                $updateId->next();
                ++$memOK;
            }
            $memOKALL += $memOK;
            echo "<div class='td2'>{$tblName} 第{$roundDB}期 公司走飞注单取消完成，共{$memOK}笔</div>";
            echo "<div class='td2'>合计共{$memOKALL}笔</div>";
            echo "<input type=button value=确定 onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
        }
        else
        {
            echo "<form action=\"op.php?op=admin&fp=delbet1_3d&gametype={$gametype}\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true;\">";
            echo "<table border=1 cellpadding=3 cellspacing=0>";
            echo "<tr class='bgClc_{$gametype}'><td>期数<td>";
            echo $rs->f['round'] . " 期 报表日期:<font color=#217952>" . $rs->f['open'] . "</font>";
            $totalNum = 0;
            $sql2 = "SELECT count(*) FROM bet_{$tbl} WHERE lotto_id = {$lottoIdTime} AND rame = 0 ";
            $rsB = getdb($sql2);
            if ($rsB->f[0])
            {
                echo "<tr class='td2'><td class='bgClc_{$gametype}'>会员下注注单<td  align=right>{$rsB->f[0]} 笔";
            }
            $totalNum += $rsB->f[0];
            $sql2 = "SELECT count(*) FROM bet2_{$tbl} WHERE lotto_id = {$lottoIdTime} AND rame = 0 ";
            $rsB = getdb($sql2);
            if ($rsB->f[0])
            {
                echo "<tr class='td2'><td class='bgClc_{$gametype}'>管理层走飞注单<td  align=right>{$rsB->f[0]} 笔";
            }
            $totalNum += $rsB->f[0];
            $sql2 = "SELECT count(*) FROM bet8_{$tbl} WHERE lotto_id = {$lottoIdTime} AND rame = 0 ";
            $rsB = getdb($sql2);
            if ($rsB->f[0])
            {
                echo "<tr class='td2'><td class='bgClc_{$gametype}'>公司走飞注单<td  align=right>{$rsB->f[0]} 笔";
            }
            $totalNum += $rsB->f[0];
            if ($totalNum)
            {
                echo "<tr class='td2'><td class='bgClc_{$gametype}'>合计<td  align=right>{$totalNum} 笔</table>";
                echo "<p>确定取消该期所有投注注单?(已经颁奖完毕注单无法取消！)</p>";
                echo "<input type=hidden name=lottoIdTime value={$lottoIdTime}>";
                echo "<input type=hidden name=dlbByLottoID value=1>";
                echo "<input type=hidden name=ok value=1>";
                echo "<input type=hidden name=gametype value={$gametype}>";
                echo "<p><input type=submit name='submit' value=确定> <input type=button name='reset' value=放弃 onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
            }
            else
            {
                echo "<tr class='td2'><td class='td2' colspan='2' style='text-align:center'>无任何可取消资料(已经颁奖完毕注单无法取消！)</table> <input type=button value=回上一页 onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
            }
            echo "</form>";
        }
    }
}
else if ($reBetTotalFlag && isset($_POST['betReflashByLottoIdFlag']))
{
    $LottoID = intval($_POST['lottoId']);
    if (0 < $LottoID)
    {
        $Lotto3dClass->ReBetTotalByLottoId($LottoID);
        echo "<p>注单重整完成!</p>";
    }
}
else if ($reBetTotalFlag && isset($_POST['betReflashFlag']))
{
    $betReflash = intval($_POST['betReflash']);
    switch ($betReflash)
    {
        case 0 :
            $Lotto3dClass->getBet_3D("0");
            $Lotto3dClass->getBet2_3D("0");
            $Lotto3dClass->getBet8_3D("0");
            break;
        case 1 :
            $Lotto3dClass->getBet_3D("0");
            break;
        case 2 :
            $Lotto3dClass->getBet2_3D("0");
            break;
        case 3 :
            $Lotto3dClass->getBet8_3D("0");
            break;
    }
    echo "<p>注单重整完成!</p>";
}
else
{
    if (isset($_POST['id']))
    {
        $bet = intval($_POST['bet']);
        $betname = "";
        if ($bet == 1)
        {
            $betfile = "bet_{$tbl}";
            $betname = "{$tblName}会员注单";
        }
        else if ($bet == 2)
        {
            $betfile = "bet2_{$tbl}";
            $betname = "{$tblName}下线走飞注单";
        }
        else if ($bet == 3)
        {
            $betfile = "bet8_{$tbl}";
            $betname = "{$tblName}公司走飞注单";
        }
        else if ($bet == 4)
        {
            $betfile = "bet_all";
            $betname = "{$tblName}管理及会员帐号全部注单";
        }
        else
        {
            $ui->showErrorPage("请选择{$tblName}注单类型！");
            exit();
        }
        if ($betfile == "bet_all")
        {
            $id = getvar("id");
            $rs = getdb("select id,acl from k_user where account='{$id}'");
            if ($rs->eof)
            {
                $ui->showErrorPage("错误的会员帐号！");
                exit();
            }
            $userid = $rs->f['id'];
            $acl = $rs->f['acl'];
            if ($acl == 1)
            {
                $userlist = $userid;
            }
            else
            {
                $userlist = GetUserList($userid);
                if ($userlist == "")
                {
                    $ui->showErrorPage("没有会员！");
                    exit();
                }
            }
            switch ($show3D3S)
            {
                case 0 :
                    $rs = getdb("select id,open,round from lotto_{$tbl} where open>='" . date("Y-m-d") . "' order by open LIMIT 0,1");
                    if ($rs->eof)
                    {
                        $ui->showErrorPage("没有建立期数！");
                        exit();
                    }
                    $lotto_id = $rs->f['id'];
                    $open = $rs->f['open'];
                    $round = $rs->f['round'];
                    $wherelottoid = "lotto_id={$lotto_id}";
                    $rs->close();
                    break;
                case 1 :
                    require_once( "class_3d/RateConfig_3d.php" );
                    $RateConfig_3d = new RateConfig_3d($gametype);
                    $openPaper = $RateConfig_3d->getPaperOpen();
                    $rs = getdb("select id,open,round from lotto_{$tbl} where open>='{$openPaper}' order by openbet");
                    if ($rs->eof)
                    {
                        $ui->showErrorPage("没有建立期数！");
                        exit();
                    }
                    $lottoidArr = array();
                    $wherelottoid = "";
                    $open = $rs->f['open'];
                    $round = $rs->f['round'];
                    while (!$rs->eof)
                    {
                        array_push($lottoidArr, $rs->f['id']);
                        $round2 = $rs->f['round'];
                        $rs->next();
                    }
                    $round .= "~" . $round2;
                    $wherelottoid = "lotto_id IN (" . implode(",", $lottoidArr) . ")";
                    $rs->close();
            }
            $rs = getdb("select count(id) from bet_{$tbl} where {$wherelottoid} and user_id in ({$userlist})");
            if ($rs->f[0] == 0)
            {
                $ui->showErrorPage("没有任何注单！");
                exit();
            }
            $betcount = $rs->f[0];
            if (isset($_POST['ok']))
            {
                getdb("update bet_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id in ({$userlist}) and rame=0");
                $updateId = getdb("select id from bet_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id in ({$userlist})");
                while (!$updateId->eof)
                {
                    $Lotto3dClass->getBet_3D($updateId->f[0]);
                    $updateId->next();
                }
                if (1 < $acl)
                {
                    getdb("update bet2_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id={$userid} and rame=0");
                    $updateId = getdb("select id from bet2_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id ={$userid}");
                    while (!$updateId->eof)
                    {
                        $Lotto3dClass->getBet2_3D($updateId->f[0]);
                        $updateId->next();
                    }
                    if ($acl == 3)
                    {
                        $userlist2 = GetUserList($userid, 2);
                        if ($userlist2 != "")
                        {
                            getdb("update bet2_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id in ({$userlist2}) and rame=0");
                        }
                        $updateId = getdb("select id from bet2_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id in ({$userlist2})");
                        while (!$updateId->eof)
                        {
                            $Lotto3dClass->getBet2_3D($updateId->f[0]);
                            $updateId->next();
                        }
                    }
                    else if ($acl == 4)
                    {
                        $userlist2 = GetUserList($userid, 2);
                        $userlist3 = GetUserList($userid, 3);
                        if ($userlist2 != "")
                        {
                            getdb("update bet2_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id in ({$userlist2}) and rame=0");
                            $updateId = getdb("select id from bet2_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id in ({$userlist2})");
                            while (!$updateId->eof)
                            {
                                $Lotto3dClass->getBet2_3D($updateId->f[0]);
                                $updateId->next();
                            }
                        }
                        if ($userlist3 != "")
                        {
                            getdb("update bet2_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id in ({$userlist3}) and rame=0");
                            $updateId = getdb("select id from bet2_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id in ({$userlist3})");
                            while (!$updateId->eof)
                            {
                                $Lotto3dClass->getBet2_3D($updateId->f[0]);
                                $updateId->next();
                            }
                        }
                    }
                    else if ($acl == 5)
                    {
                        $userlist2 = GetUserList($userid, 2);
                        $userlist3 = GetUserList($userid, 3);
                        $userlist4 = GetUserList($userid, 4);
                        if ($userlist2 != "")
                        {
                            getdb("update bet2_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id in ({$userlist2}) and rame=0");
                            $updateId = getdb("select id from bet2_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id in ({$userlist2})");
                            while (!$updateId->eof)
                            {
                                $Lotto3dClass->getBet2_3D($updateId->f[0]);
                                $updateId->next();
                            }
                        }
                        if ($userlist3 != "")
                        {
                            getdb("update bet2_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id in ({$userlist3}) and rame=0");
                            $updateId = getdb("select id from bet2_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id in ({$userlist3})");
                            while (!$updateId->eof)
                            {
                                $Lotto3dClass->getBet2_3D($updateId->f[0]);
                                $updateId->next();
                            }
                        }
                        if ($userlist4 != "")
                        {
                            getdb("update bet2_{$tbl} set rame=2,state=0 where {$wherelottoid} and user_id in ({$userlist4}) and rame=0");
                            $updateId = getdb("select id from bet2_{$tbl} where rame=2 and state=0 and {$wherelottoid} and user_id in ({$userlist4})");
                        }
                        while (!$updateId->eof)
                        {
                            $Lotto3dClass->getBet2_3D($updateId->f[0]);
                            $updateId->next();
                        }
                    }
                }
                echo "<p>注单全部取消完成!</p>";
            }
            else
            {
                $name = "会员";
                if ($acl == 2)
                {
                    $name = "代理";
                }
                else if ($acl == 3)
                {
                    $name = "总代理";
                }
                else if ($acl == 4)
                {
                    $name = "股东";
                }
                else if ($acl == 5)
                {
                    $name = "大股东";
                }
                echo "<form action=\"op.php?op=admin&fp=delbet1_3d&gametype={$gametype}\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
                echo "<table border=1 cellpadding=3 cellspacing=0>";
                echo "<tr><td class=td0>期数<td>";
                echo "{$round} 期 报表日期:<font color=#217952>{$open}</font>";
                echo "<tr><td class=td0>会员下注笔数<td  align=right>{$betcount}</table>";
                echo "<p>确定取消这位{$name} {$id}所属全部{$tblName}会员的注单？</p>";
                echo "<input type=hidden name=id value={$id}>";
                echo "<input type=hidden name=bet value={$bet}>";
                echo "<input type=hidden name=ok value=1>";
                echo "<input type=hidden name=gametype value={$gametype}>";
                echo "<p><input type=submit value=确定> <input type=button value=放弃 onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
                echo "</form>";
            }
        }
        else
        {
            switch ($show3D3S)
            {
                case 0 :
                    $rs = getdb("select id,open,round from lotto_{$tbl} where open>='" . date("Y-m-d") . "' order by open");
                    break;
                case 1 :
                    $rs = getdb("select id,open,round from lotto_{$tbl} where '" . date("Y-m-d H:i:s") . "' between startbet and stopbet order by open LIMIT 0,1");
                    break;
            }
            if ($rs->eof)
            {
                $ui->showErrorPage("没有建立{$tblName}期数！");
                exit();
            }
            $lotto_id = $rs->f['id'];
            $rs->close();
            if (is_array($_POST['id']))
            {
                $id = implode(",", $_POST['id']);
            }
            else
            {
                $id = $_POST['id'];
            }
            if (strchr($id, ","))
            {
                $rs = getdb("select * from {$betfile} where id in ({$id})");
                if ($rs->eof)
                {
                    $ui->showErrorPage("错误的{$tblName}注单编号群组！");
                    exit();
                }
                if (0 < $rs->f['rame'] && $rs->f['rame'] != 2)
                {
                    $ui->showErrorPage("{$tblName}已经颁奖完毕注单无法取消！");
                    exit();
                }
                if ($rs->f['rame'] == 2)
                {
                    $ui->showErrorPage("{$tblName}已经是被取消的注单群组！");
                    exit();
                }
                if (isset($_POST['ok']))
                {
                    getdb("update {$betfile} set rame=2,state=0 where id in ({$id}) and rame=0");
                    $updateId = getdb("!!select id from {$betfile} where rame=2 and id in ({$id})");
                    while (!$updateId->eof)
                    {
                        switch ($betfile)
                        {
                            case "bet_{$tbl}" :
                                $Lotto3dClass->getBet_3D($updateId->f[0]);
                                break;
                            case "bet2_{$tbl}" :
                                $Lotto3dClass->getBet2_3D($updateId->f[0]);
                                break;
                            case "bet8_{$tbl}" :
                                $Lotto3dClass->getBet8_3D($updateId->f[0]);
                                break;
                        }
                        $updateId->next();
                    }
                    echo "<p>注单取消完成!</p>";
                }
                else
                {
                    echo "<form action=\"op.php?op=admin&fp=delbet1_3d&gametype={$gametype}\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
                    echo "<table class='tblMy3D'>";
                    echo "<tr class='td2'><td class=bgClc_{$gametype} colspan='2'><b>{$tblName} {$betname} 取消</b>";
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>{$tblName}注单编号群<td>{$id}";
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>时间<td>" . date("m-d H:i:s", $rs->f['createtime']);
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>期数<td>";
                    $lottoRS = getdb("SELECT * FROM lotto_{$tbl} WHERE id = " . $rs->f['lotto_id']);
                    echo $lottoRS->f['round'] . " 期 <font color=#217952>" . $lottoRS->f['open'] . "</font>";
                    if ($show3D3S == 0)
                    {
                        $stopbet = $conf->get("stopbet_{$tbl}");
                        $t = $lottoRS->f['open'] . " " . substr($stopbet, 0, 2) . ":" . substr($stopbet, 2);
                    }
                    else
                    {
                        $t = $lottoRS->f['stopbet'];
                    }
                    $t = strtotime($t);
                    $n = $lottoRS->f['n1'] + $lottoRS->f['n2'] + $lottoRS->f['n3'];
                    if ($show3D3S == 0 && $conf->get("calcbet_{$tbl}") == 1)
                    {
                        echo "<p><font color=red>{$tblName}已经在颁奖过帐中，注单无法取消！</font></p>";
                    }
                    else if ($show3D3S == 1 && $lottoRS->f['calcbet'] == 1)
                    {
                        echo "<p><font color=red>{$tblName} 第" . $lottoRS->f['round'] . "期 已经在颁奖过帐中，注单无法取消！</font></p>";
                    }
                    else if ($t <= systime() || 0 - 3 < $n)
                    {
                        echo "<p><font color=red>超过截止下注时间，该笔{$tblName}注单无法取消！</font></p>";
                    }
                    else
                    {
                        echo "<p>确定取消这些{$tblName} {$betname}群组？</p>";
                        echo "<input type=hidden name=id value={$id}>";
                        echo "<input type=hidden name=bet value={$bet}>";
                        echo "<input type=hidden name=ok value=1>";
                        echo "<input type=hidden name=gametype value={$gametype}>";
                        echo "<p><input type=submit value=确定> <input type=button value=放弃 onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
                    }
                    echo "</form>";
                }
            }
            else
            {
                $id = intval($id);
                if ($id == 0)
                {
                    $ui->showErrorPage("错误的{$tblName}注单编号！");
                    exit();
                }
                $rs = getdb("select * from {$betfile} where id={$id}");
                if ($rs->eof)
                {
                    $ui->showErrorPage("错误的{$tblName}注单编号！");
                    exit();
                }
                if ($rs->f['rame'] != 2)
                {
                    $ui->showErrorPage("{$tblName}已经颁奖完毕注单无法取消！");
                    exit();
                }
                if ($rs->f['rame'] == 2)
                {
                    $ui->showErrorPage("{$tblName}已经是被取消的注单！");
                    exit();
                }
                if (isset($_POST['ok']))
                {
                    if (0 < $rs->f['rame'] && $rs->f['rame'] != 2)
                    {
                        echo "{$tblName}已经颁奖完毕注单无法取消！";
                    }
                    else
                    {
                        if ($rs->f['rame'] == 2)
                        {
                            echo "{$tblName}已经是被取消的注单！";
                        }
                        else
                        {
                            getdb("update {$betfile} set rame=2,state=0 where id={$id} and rame=0");
                            $updateId = getdb("select id from {$betfile} where rame=2 and id={$id}");
                            while (!$updateId->eof)
                            {
                                switch ($betfile)
                                {
                                    case "bet_{$tbl}" :
                                        $Lotto3dClass->getBet_3D($updateId->f[0]);
                                        break;
                                    case "bet2_{$tbl}" :
                                        $Lotto3dClass->getBet2_3D($updateId->f[0]);
                                        break;
                                    case "bet8_{$tbl}" :
                                        $Lotto3dClass->getBet8_3D($updateId->f[0]);
                                        break;
                                }
                                $updateId->next();
                            }
                            echo "<p>" . $tblName . "注单取消完成!</p>";
                        }
                    }
                }
                else
                {
                    echo "<form action=\"op.php?op=admin&fp=delbet1_3d&gametype={$gametype}\" method=post onsubmit=\"this.submit.disabled=true;this.reset.disabled=true\">";
                    echo "<input type=hidden name=gametype value={$gametype}>";
                    echo "<table class='tblMy3D'>";
                    echo "<tr class='td2'><td class=bgClc_{$gametype} colspan=2><b>{$tblName} {$betname} 取消</b><br>";
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>{$tblName}注单编号<td>{$id}";
                    if ($bet < 3)
                    {
                        $u = get_user($rs->f['user_id']);
                        if ($bet == 1)
                        {
                            echo "<tr class='td2'><td class=bgClc_{$gametype}>会员帐号<td>" . $u['account'];
                        }
                        else
                        {
                            $acl = $u['acl'];
                            $name = "";
                            if ($acl == 2)
                            {
                                $name = "代理";
                            }
                            else if ($acl == 3)
                            {
                                $name = "总代理";
                            }
                            else if ($acl == 4)
                            {
                                $name = "股东";
                            }
                            else if ($acl == 5)
                            {
                                $name = "大股东";
                            }
                            echo "<tr class='td2'><td class=bgClc_{$gametype}>" . $name . "帐号<td>" . $u['account'];
                        }
                    }
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>时间<td>" . date("m-d H:i:s", $rs->f['createtime']);
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>期数<td>";
                    $lottoRS = getdb("SELECT * FROM lotto_{$tbl} WHERE id = " . $rs->f['lotto_id']);
                    echo $lottoRS->f['round'] . " 期 <font color=#217952>" . $lottoRS->f['open'] . "</font>";
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>注单内容<td>" . $g_betname_3d[$rs->f['bettype']] . " " . $rs->f['line_nums'];
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>赔率<td>" . show_rate($rs->f['bettype'], $rs->f['rate']);
                    if ($bet == 3)
                    {
                        echo "<tr class='td2'><td class=bgClc_{$gametype}>退水<td>" . $rs->f['back'];
                    }
                    echo "<tr class='td2'><td class=bgClc_{$gametype}>金额<td>" . $rs->f['amount'];
                    echo "</table>";
                    if ($show3D3S == 0)
                    {
                        $stopbet = $conf->get("stopbet_{$tbl}");
                        $t = $lottoRS->f['open'] . " " . substr($stopbet, 0, 2) . ":" . substr($stopbet, 2);
                    }
                    else
                    {
                        $t = $lottoRS->f['stopbet'];
                    }
                    $t = strtotime($t);
                    $n = $lottoRS->f['n1'] + $lottoRS->f['n2'] + $lottoRS->f['n3'];
                    if ($show3D3S == 0 && $conf->get("calcbet_{$tbl}") == 1)
                    {
                        echo "<p><font color=red>{$tblName}已经在颁奖过帐中，注单无法取消！</font></p>";
                    }
                    else if ($show3D3S == 1 && $lottoRS->f['calcbet'] == 1)
                    {
                        echo "<p><font color=red>{$tblName}已经在颁奖过帐中，注单无法取消！</font></p>";
                    }
                    else if ($t <= systime() || 0 - 3 < $n)
                    {
                        echo "<p><font color=red>{$tblName}超过截止下注时间，该笔注单无法取消！</font></p>";
                    }
                    else
                    {
                        echo "<p>确定取消这笔 {$betname}？</p>";
                        echo "<input type=hidden name=id value={$id}>";
                        echo "<input type=hidden name=bet value={$bet}>";
                        echo "<input type=hidden name=ok value=1>";
                        echo "<p><input type=submit value=确定> <input type=button value=放弃 onclick=\"location.href='op.php?op=admin&fp=delbet1_3d&gametype={$gametype}'\">";
                    }
                    echo "</form>";
                }
            }
        }
    }
    else
    {
        if ($conf->get("systemcheck_{$tbl}") == 0)
        {
            $tempStr = "disabled=disabled";
        }
        else
        {
            $tempStr = "";
        }
        echo "<font color=red><b>{$tblName}注单取消</b></font><br>";
        echo "<form action=\"op.php?op=admin&fp=delbet1_3d&gametype={$gametype}\" method=post onsubmit=\"this.submit.disabled=true\">";
        echo "<input type=radio name=bet value=1 checked id=rdobet1><label for=rdobet1>会员注单</label>&#12288;<input type=radio name=bet value=2 id=rdobet2><label for=rdobet2>下线走飞注单</label>&#12288;<input type=radio name=bet value=3 id=rdobet3><label for=rdobet3>公司走飞注单</label>&#12288;<input type=radio name=bet value=4 id=rdobet4><label for=rdobet4>管理层全部注单</label><br><br>";
        echo "请输入{$tblName}注单编号：<input name=id>";
        echo "<input type=hidden name=gametype value={$gametype}>";
        echo "<input type=submit value=确定>";
        echo "</form>";
        $sql = "SELECT id, open, round" . ( $show3D3S ? ", startbet, stopbet" : "" ) . " FROM lotto_{$tbl} where open = '{$todayOpen}' " . ( $show3D3S ? "AND '" . date("Y-m-d H:i:s") . "' between startbet and stopbet" : "" ) . " LIMIT 1";
        $rs = getdb($sql);
        if (!$rs->eof)
        {
            echo "<form method='get' action='op.php' >";
            echo "<input type='hidden' name='op' value='admin' />";
            echo "<input type='hidden' name='fp' value='delbet1_3d' />";
            echo "<input type='hidden' name='gametype' value='{$gametype}' />";
            echo "<fieldset class='td2'><legend class='bgImg_{$gametype}' style='padding:5px;'>指定帐号勾选取消 {$tblName} 注单 </legend>";
            echo "<div>第" . $rs->f['round'] . "期 " . $rs->f['open'];
            if ($show3D3S)
            {
                echo " (" . substr($rs->f['startbet'], 0 - 8) . " 开盘 ~ " . substr($rs->f['stopbet'], 0 - 8) . " 关盘)</div>";
            }
            echo "<div>";
            echo "请输入(会员/管理层 )帐号: <input type='text' name='fineAcc' />";
            $betname = judge_type($gametype);
            echo "<select name='bettypesubid'>";
            echo "<option value='-1'>不限类别</option>";
            foreach ($betname as $betnameKey => $betnameVal)
            {
                echo "<option value='{$betnameKey}'>{$betnameVal}</option>";
            }
            echo "</select>";
            echo "<input type='submit' value='查询' />";
            echo "<input type='hidden' name='fineAccID' value='1' />";
            echo "</div>";
        }
        echo "<div>1) 已颁奖之注单无法取消。</div>";
        echo "<div>2) 会员帐号列出下注注单、管理层帐号列出走飞注单。</div>";
        echo "</fieldset>";
        echo "</form>";
        if ($show3D3S)
        {
            echo "<form method=post >";
            echo "<fieldset class='td2'><legend class='bgImg_{$gametype}' style='padding:5px;'>取消 {$tblName} 某期期数全部注单</legend>";
            echo "请选择期数[{$tblName}]:";
            $sql = "SELECT id, open, round, startbet, stopbet FROM lotto_{$tbl} where open = '{$todayOpen}' AND startbet <= '" . date("Y-m-d H:i:s") . "' ORDER BY id DESC";
            $rs = getdb($sql);
            if (!$rs->eof)
            {
                echo "<select name=\"lottoIdTime\">";
                while (!$rs->eof)
                {
                    echo "<option value=\"" . $rs->f['id'] . "\">第" . $rs->f['round'] . "期 " . $rs->f['open'] . " (" . substr($rs->f['startbet'], 0 - 8) . " 开盘 ~ " . substr($rs->f['stopbet'], 0 - 8) . " 关盘)</option>";
                    $rs->next();
                }
                echo "</select>";
                echo "<input type='submit' value='取消该期全部注单' />";
                echo "<input type='hidden' name='dlbByLottoID' value='1' />";
            }
            echo "<div>1) 已颁奖之注单无法取消。</div>";
            echo "<div>2) 该期所有会员下注注单、管理层走飞注单、公司走飞注单都会取消。</div>";
            echo "</fieldset>";
            echo "</form>";
        }
        if ($reBetTotalFlag)
        {
            echo "<form action=\"op.php?op=admin&fp=delbet1_3d&gametype={$gametype}\" method=post onsubmit=\"this.submit.disabled=true\">";
            echo " <fieldset>\r\n              <legend>{$tblName}注单重整(仅适用於手动後台取消注单时，不指定期数。需rame=2, state=0)</legend>\r\n              <input type=radio name=betReflash value=0 checked id=rdobetReflash0><label for=rdobetReflash0>全部注单</label>\r\n              <input type=radio name=betReflash value=1 id=rdobetReflash1><label for=rdobetReflash1>会员注单</label>\r\n              <input type=radio name=betReflash value=2 id=rdobetReflash2><label for=rdobetReflash2>管理层走飞注单</label>\r\n              <input type=radio name=betReflash value=3 id=rdobetReflash3><label for=rdobetReflash3>公司走飞注单</label>\r\n            <input type=\"submit\" value=\"注单重整\" {$tempStr} />\r\n            </fieldset>";
            echo "<input type=\"hidden\" name=\"betReflashFlag\" value=\"1\" />";
            echo "<input type=hidden name=gametype value={$gametype}>";
            echo "</form>";
            echo "<form action=\"op.php?op=admin&fp=delbet1_3d\" method=\"post\" >";
            echo " <fieldset>\r\n              <legend>{$tblName}注单全部重新整理(指定期数)</legend>\r\n            ";
			if($gametype==1 || $gametype ==2)
				$sql = "SELECT id,open,round FROM lotto_{$tbl} WHERE open <='".date("Y-m-d")."' ORDER BY id DESC LIMIT 0,3";
			else
            	$sql = "SELECT id,open,round FROM lotto_{$tbl} WHERE open != '0000-00-00' and stopbet<='".date('Y-m-d H:i:s')."' ORDER BY id DESC LIMIT 0,3";
			$rs = getdb($sql);
            if (!$rs->eof)
            {
                echo "<select name=\"lottoId\">";
                while (!$rs->eof)
                {
                    echo "<option value=\"" . $rs->f['id'] . "\">第" . $rs->f['round'] . "期 " . $rs->f['open'] . "</option>";
                    $rs->next();
                }
                echo "</select>";
                echo "&nbsp;<input type=\"submit\" value=\"注单重整\"/>";
                echo "<input type=\"hidden\" name=\"betReflashByLottoIdFlag\" value=\"1\" />";
                echo "<input type=hidden name=gametype value={$gametype}>";
                echo "<ul style=\"color:red;\">※注意：({$tblName}系统维护中才可重整)\r\n              <li>重整时自动赔率将重新计算</li>\r\n              <li>重整时自动走飞将以目前最新赔率及走飞限额为计算依据，如果已颁奖请重新颁奖。</li>\r\n              </ul>";
            }
            else
            {
                echo "<p>无任何{$tblName}期数</p>";
            }
            echo "</fieldset>";
            echo "</form>";
        }
    }
}
echo "</td></tr></table>";
$ui->footer();
?>